package com.charger.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.charger.common.annotation.Log;
import com.charger.common.core.controller.BaseController;
import com.charger.common.core.domain.AjaxResult;
import com.charger.common.enums.BusinessType;
import com.charger.domain.Dispose;
import com.charger.service.IDisposeService;
import com.charger.common.utils.poi.ExcelUtil;
import com.charger.common.core.page.TableDataInfo;

/**
 * 隐患故障处理Controller
 *
 * @author xuan
 * @date 2024-11-28
 */
@RestController
@RequestMapping("/system/dispose")
public class DisposeController extends BaseController {
    @Autowired
    private IDisposeService disposeService;

    /**
     * 查询隐患故障处理列表
     */
    @PreAuthorize("@ss.hasPermi('system:dispose:list')")
    @GetMapping("/list")
    public TableDataInfo list(Dispose dispose) {
        startPage();
        List<Dispose> list = disposeService.selectDisposeList(dispose);
        return getDataTable(list);
    }

    /**
     * 导出隐患故障处理列表
     */
    @PreAuthorize("@ss.hasPermi('system:dispose:export')")
    @Log(title = "隐患故障处理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Dispose dispose) {
        List<Dispose> list = disposeService.selectDisposeList(dispose);
        ExcelUtil<Dispose> util = new ExcelUtil<Dispose>(Dispose.class);
        util.exportExcel(response, list, "隐患故障处理数据");
    }

    /**
     * 获取隐患故障处理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:dispose:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(disposeService.selectDisposeById(id));
    }

    /**
     * 新增隐患故障处理
     */
    @PreAuthorize("@ss.hasPermi('system:dispose:add')")
    @Log(title = "隐患故障处理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Dispose dispose) {
        return toAjax(disposeService.insertDispose(dispose));
    }

    /**
     * 修改隐患故障处理
     */
    @PreAuthorize("@ss.hasPermi('system:dispose:edit')")
    @Log(title = "隐患故障处理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Dispose dispose) {
        return toAjax(disposeService.updateDispose(dispose));
    }

    /**
     * 删除隐患故障处理
     */
    @PreAuthorize("@ss.hasPermi('system:dispose:remove')")
    @Log(title = "隐患故障处理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(disposeService.deleteDisposeByIds(ids));
    }
}
